package com.honghu.villagepost.adapter

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.honghu.villagepost.R
import com.honghu.villagepost.entity.Select

/**
 * @author: mqwang
 * @create: 3/4/21 11:41 AM
 * @Description:
 */
class ItemTypeAdapter : BaseQuickAdapter<Select, BaseViewHolder>(R.layout.adapter_item_type) {
    override fun convert(helper: BaseViewHolder?, item: Select?) {
        if (item!!.isSelect) {
            helper!!.setBackgroundRes(R.id.tv_content, R.drawable.bg_orange_16)
            helper!!.setTextColor(R.id.tv_content, mContext.resources.getColor(R.color.colorOrange))
        } else {
            helper!!.setBackgroundRes(R.id.tv_content, R.drawable.bg_e4e4e4_16)
            helper!!.setTextColor(R.id.tv_content, mContext.resources.getColor(R.color.color_text_search))
        }

        helper.setText(R.id.tv_content, item.name)

    }

    fun selectItem(position: Int): Select {
        for (element in data) {
            element.isSelect = false
        }
        val item = data.get(position)
        item.isSelect = true
        notifyDataSetChanged()
        return item
    }

}